using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime.Tracking;

namespace OpenComposite.EII.Simulation
{
	public class SimulationTrackingChannel : TrackingChannel
	{
		#region Initialization
		public SimulationTrackingChannel(TrackingParameters parameters) : base()
		{
			_parameters = parameters;
		}
		#endregion

		#region Override TrackingChannel
		protected override void InstanceCompletedOrTerminated()
		{
			// send CompletedOrTerminated event
			EventHandler<SimulationTrackingEventArgs> tmp = this.CompletedOrTerminated;
			if ( tmp != null )
				tmp(this, new SimulationTrackingEventArgs(_parameters, null));
		}

		protected override void Send(TrackingRecord record)
		{
			// send Tracking event
			EventHandler<SimulationTrackingEventArgs> tmp = this.Tracking;
			if ( tmp != null )
				tmp(this, new SimulationTrackingEventArgs(_parameters, record));
		}
		#endregion

		#region Public Members

		#region Events
		public event EventHandler<SimulationTrackingEventArgs> Tracking = null;
		public event EventHandler<SimulationTrackingEventArgs> CompletedOrTerminated = null;
		#endregion

		#endregion

		#region Private Members

		#region Variables
		private TrackingParameters _parameters;
		#endregion

		#endregion
	}

	#region Class: SimulationTrackingEventArgs : BaseClass: EventArgs
	public class SimulationTrackingEventArgs : EventArgs
	{
		private readonly TrackingRecord _record;
		private readonly TrackingParameters _parameters;

		public SimulationTrackingEventArgs(TrackingParameters parameters, TrackingRecord record)
		{
			_record = record;
			_parameters = parameters;
		}

		public TrackingRecord Record
		{
			get { return _record; }
		}
		public TrackingParameters Parameters
		{
			get { return _parameters; }
		}
	}
	#endregion
}
